API key
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top
An application programming interface (API) key is a secret unique identifier used to authenticate and authorize a user, developer, or calling program to an API.cite-ref-0-1-0[1]cite-ref-3-2-0[2]
Cloud computing providers such as Google Cloud Platform and Amazon Web Services recommend that API keys only be used to authenticate projects, rather than human users.cite-ref-3[3]cite-ref-4[4]
Contents
• Usage
• Security
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Usage
HTTP APIs
The access token is often a JSON Web Token (JWT) in the HTTP Authorization header:
POST /something HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
In the query string:
POST /something?api_key=abcdef12345 HTTP/1.1
As a request header:
GET /something HTTP/1.1
X-API-Key: abcdef12345
As a cookie:
GET /something HTTP/1.1
Cookie: X-API-KEY=abcdef12345
Security
API keys are generally not considered secure; they are typically accessible to clients, making it easy for someone to steal an API key. Keys often have no expiration, meaning a stolen key can be used indefinitely unless revoked or regenerated.cite-ref-1-6-0[6] Keys are supposed to be a secret known only by the client and server, so they should not be communicated over an insecure channel and can only be considered secure when used in conjunction with other security mechanisms such as HTTPS.cite-ref-2-5-1[5]
There are several risk scenarios when using API keys:
• Developers may hard-code keys into source code, and forget that when they release the code.cite-ref-3-2-2[2]
• Having unprotected keys in mobile apps is dangerous.cite-ref-3-2-3[2]
These risks generally stem from the key being in plaintext, which is potentially accessible to adversaries.cite-ref-3-2-4[2]
Incidents
References
cite-note-0-11. ↑ "API Key - What is an API Key?". Last Call - RapidAPI Blog. Retrieved 2019-09-20.
cite-note-33. ↑ "What is an API Key? - API Keys and Tokens Explained - AWS". Amazon Web Services, Inc. Retrieved 2024-09-01.
cite-note-44. ↑ "Why and when to use API keys | Cloud Endpoints with OpenAPI". Google Cloud. Retrieved 2024-09-01.
cite-note-2-55. ↑ "API Keys". Archived from the original on 2019-10-17.
cite-note-1-66. ↑ "Why and when to use API keys | Cloud Endpoints with OpenAPI". Google Cloud. Retrieved 2019-09-20.
Book sources
External links